package com.cmbc.connect;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author lmw
 */
@ToString
@Getter
@Setter
public abstract class AbstractMessageSender implements IMesseageSender {
    private SM2Encrypter encrypter;

    private String url;

    private String merchantNo;

    /**
     * 添加头信息
     * 
     * @param message
     * @param channelJnlNo
     */
    protected void addHeader(Map<String, Object> message, String channelJnlNo) {
        if (message.containsKey(Constant.ChannelHeadRequest)) {
            return;
        }

        String nowDate = new SimpleDateFormat("yyyyMMdd").format(new Date());

        Map<String, Object> headerMap = new HashMap<>(16);
        headerMap.put(Constant.ChannelId, this.getMerchantNo());
        headerMap.put(Constant.ChannelDate, nowDate);
        headerMap.put(Constant.ChannelJnlNo, channelJnlNo);
        headerMap.put(Constant.ClientIpAddr, message.get(Constant.ClientIpAddr));
        message.put(Constant.ChannelHeadRequest, headerMap);
    }

    protected void addSendTransCode(String sendTransCode, Map<String, Object> message) {
        message.put(Constant.SendTransCode, sendTransCode);
    }
}
